local ClientOHOH = _G.ClientOHOH;
local M = ClientOHOH.class.new(script, ClientOHOH.files.ModelObject());
local CallBackManager = ClientOHOH.load.CallBackManager();
local BigNumberHelper = ClientOHOH.load.BigNumberHelper();
local PlayerInfoHelper=_G.ClientOHOH.load.PlayerInfoHelper()


function M.new(...)
	return M(...);
end;

function M.ctor(self,model,title,fullFuc)--构造函数

	assert(model,"model==nul")

	M.super.ctor(self, model);
	
	ClientOHOH:GetPath_Loop("title.SurfaceGui.Frame.TextLabel",model).Text=title
	self.RankList={}
	self.cell=ClientOHOH:GetPath_Loop("rank.SurfaceGui.Main.ScrollingFrame.cell",model)
	table.insert(self.RankList,ClientOHOH:GetPath_Loop("rank.SurfaceGui.Main.ScrollingFrame.1",model))
	table.insert(self.RankList,ClientOHOH:GetPath_Loop("rank.SurfaceGui.Main.ScrollingFrame.2",model))
	table.insert(self.RankList,ClientOHOH:GetPath_Loop("rank.SurfaceGui.Main.ScrollingFrame.3",model))	
	
	self.th1=ClientOHOH:GetPath_Loop("rank.SurfaceGui.Main.head.1th.Icon",model)
	self.th2=ClientOHOH:GetPath_Loop("rank.SurfaceGui.Main.head.2th.Icon",model)
	self.th3=ClientOHOH:GetPath_Loop("rank.SurfaceGui.Main.head.3rd.Icon",model)

	self.th1.Image=""
	self.th2.Image=""
	self.th3.Image=""

	self.fullFuc=fullFuc
end;


function M.Update(self,data)-- 更新数据
	for k,v in pairs(data) do


		-- if not v.head then
		-- 	v.head=""
		-- end

		-- if not v.name then
		-- 	v.name="userId_"..v.key
		-- end

		local cell=nil
		if self.RankList[k] then
			cell=self.RankList[k]
		else
			cell=self.cell:Clone()
			cell.Parent=self.cell.Parent
			self.RankList[k]=cell
			-- table.insert(self.RankList,cell)
		end
		cell.Visible=true
		
		PlayerInfoHelper.GetPlayerInfo(v.key,function(headImage,name)
			if self.fullFuc then
				self.fullFuc({cell.name,name},{cell.value,v.value},{cell.rank,k})
			else
				cell.name.Text=name
				cell.value.Text=BigNumberHelper:ToString(v.value)
				cell.rank.Text=k
			end
	
			if k==1 then
				self.th1.Image=headImage
			elseif k==2 then
				self.th2.Image=headImage
			elseif k==3 then
				self.th3.Image=headImage
			end

		end)




		
	end

end;




function M.dtor(self)--析构函数
	M.super.dtor(self);
end;

return M